/*
 * WXTests.m
 * This file is part of WX
 *
 * Copyright 2010-2013 Jason Coulls. All Rights Reserved.
 *
 * is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 2 of the License.
 *
 * is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with . If not, see <http://www.gnu.org/licenses>.
 */


#import <XCTest/XCTest.h>
#import "WX.h"

@interface WXTests : XCTestCase

@end

@implementation WXTests

#pragma mark - Setup/TearDown

- (void)setUp
{
    [super setUp];
    // Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown
{
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    [super tearDown];
}

#pragma mark - Temperature Tests

- (void)testTempConversionCtoC
{
    Temperature *cTemp = [[Temperature alloc]init];
    cTemp.temperatureScale = kTEMPSCALECELSIUS;
    cTemp.reading = 10.421;
    
    //This should be the same (i.e. no conversion).
    double newTemp = [cTemp celsiusValue];
    XCTAssertEqual(cTemp.reading, newTemp,
                   @"Conversion of Celsius to Celsius does not match.");

}

- (void)testTempConversionFtoF
{
    Temperature *fTemp = [[Temperature alloc]init];
    fTemp.temperatureScale = kTEMPSCALEFAHRENHEIT;
    fTemp.reading = 10.421;
    
    //This should be the same (i.e. no conversion).
    double newTemp = [fTemp fahrenheitValue];
    XCTAssertEqual(fTemp.reading, newTemp,
                   @"Conversion of Fahrenheit to Fahrenheit does not match.");
    
}

- (void)testTempConversionFtoC
{
    Temperature *fTemp = [[Temperature alloc]init];
    fTemp.temperatureScale = kTEMPSCALEFAHRENHEIT;
    fTemp.reading = 0;
    
    //-0F should be -32C.
    XCTAssertEqual([fTemp celsiusValue] , (double)-32,
                   @"Conversion of Fahrenheit to Celsius failed.");
    
}

- (void)testTempConversionKelvintoC
{
    Temperature *fTemp = [[Temperature alloc]init];
    fTemp.temperatureScale = KTEMPSCALEKELVIN;
    fTemp.reading = 1;
    
    //1 kelvin should be -272.15C.
    XCTAssertEqual([fTemp celsiusValue] , (double)-272.15,
                   @"Conversion of kelvin to Celsius failed.");
    
}

- (void)testTempConversionKelvintoF
{
    Temperature *fTemp = [[Temperature alloc]init];
    fTemp.temperatureScale = KTEMPSCALEKELVIN;
    fTemp.reading = 1;
    
    //1 kelvin should be -457.87F.
    NSString *F = [NSString stringWithFormat:@"%2.2f",[fTemp fahrenheitValue]];
    
    XCTAssertTrue([F isEqualToString:@"-457.87"],
                   @"Conversion of kelvin to fahrenheit failed.");
    
}

- (void)testTempConversionFtoKelvin
{
    Temperature *fTemp = [[Temperature alloc]init];
    fTemp.temperatureScale = kTEMPSCALEFAHRENHEIT;
    fTemp.reading = 1;
    
    //1 kelvin should be 255.93F.
    NSString *K = [NSString stringWithFormat:@"%2.2f",[fTemp kelvinValue]];
    XCTAssertTrue([K isEqualToString:@"255.93"],
                   @"Conversion of Fahrenheit to kelvin failed.");
    
}

#pragma mark - Wind Tests


-(void) testWindMPHtoKMH
{
    Wind *w = [[Wind alloc] init];
    w.reading = 10;
    w.speedScale = kSPEEDMPH;
    
    //10MPH should be 16.0934KPH
    NSString *speed = [NSString stringWithFormat:@"%2.4f", [w speedInKMH]];
    XCTAssertTrue([speed isEqualToString:@"16.0934"],
                  @"Conversion of Wind MPH to KMH failed.");
}


-(void) testWindMPHtoKnots
{
    Wind *w = [[Wind alloc] init];
    w.reading = 10;
    w.speedScale = kSPEEDMPH;
    
    //10MPH should be 8.68976 Knots
    NSString *speed = [NSString stringWithFormat:@"%2.5f", [w speedInKnots]];
    XCTAssertTrue([speed isEqualToString:@"8.68976"],
                  @"Conversion of Wind MPH to Knots failed.");
    
}


-(void) testWindKMHtoMPH
{
    Wind *w = [[Wind alloc] init];
    w.reading = 10;
    w.speedScale = kSPEEDKMH;
    
    //10KMH should be 6.21371 MPH
    NSString *speed = [NSString stringWithFormat:@"%5.5f", [w speedInMPH]];
    XCTAssertTrue([speed isEqualToString:@"6.21371"],
                  @"Conversion of Wind KMH to MPH failed.");

}

-(void) testWindKMHtoKnots
{
    Wind *w = [[Wind alloc] init];
    w.reading = 10;
    w.speedScale = kSPEEDKMH;
    
    //10KMH should be 5.39957 Knots
    NSString *speed = [NSString stringWithFormat:@"%2.5f", [w speedInKnots]];
    XCTAssertTrue([speed isEqualToString:@"5.39957"],
                  @"Conversion of Wind KMH to knots failed.");
    
}


-(void) testWindKnotstoMPH
{
    Wind *w = [[Wind alloc] init];
    w.reading = 10;
    w.speedScale = KSPEEDKNOTS;
    
    //10Knots should be 11.50779 MPH
    NSString *speed = [NSString stringWithFormat:@"%2.5f", [w speedInMPH]];
    XCTAssertTrue([speed isEqualToString:@"11.50779"],
                  @"Conversion of Wind KMH to knots failed.");
 
}


-(void) testWindKnotsToKMH
{
    Wind *w = [[Wind alloc] init];
    w.reading = 10;
    w.speedScale = KSPEEDKNOTS;
    
    //10Knots should be 18.52 KMH
    NSString *speed = [NSString stringWithFormat:@"%2.2f", [w speedInKMH]];
    XCTAssertTrue([speed isEqualToString:@"18.52"],
                  @"Conversion of Wind knots to KMH failed.");

}


#pragma mark - Pressure Tests

-(void) testPressurekPaToPa
{
    Pressure *pressure = [[Pressure alloc] init];
    pressure.pressureScale = kPRESSUREKILOPASCALS;
    pressure.reading = 101.325;
    
    //101.325 kpa should be 101325pa.
    double result = [pressure pressureInPascals];
    XCTAssertEqual(result, (double)101325,
                   @"Converting pressure in kPa to Pascals is failing.");
    
}

-(void) testPressurePaTokPa
{
    Pressure *pressure = [[Pressure alloc] init];
    pressure.pressureScale = kPRESSUREPASCALS;
    pressure.reading = 101325;
    
    //101325pa should be 101.325kpa.
    double result = [pressure pressureInKilopascals];
    XCTAssertEqual(result, (double)101.325,
                   @"Converting pressure in Pa to kPa is failing.");
    
}

-(void) testPressurePaToMb
{
    Pressure *pressure = [[Pressure alloc] init];
    pressure.pressureScale = kPRESSUREPASCALS;
    pressure.reading = 101325;
    
    //101325pa should be 1013.25 Mb.
    double result = [pressure pressureInMillibars];
    XCTAssertEqual(result, (double)1013.25,
                   @"Converting pressure in Pa to Mb is failing.");
    
}

-(void) testPressurePaTohPa
{
    Pressure *pressure = [[Pressure alloc] init];
    pressure.pressureScale = kPRESSUREPASCALS;
    pressure.reading = 101325;
    
    //101325pa should be 1013.25 hPa.
    double result = [pressure pressureInHectopascals];
    XCTAssertEqual(result, (double)1013.25,
                   @"Converting pressure in Pa to hPa is failing.");
    
}


-(void) testPressurePaToInHg
{
    Pressure *pressure = [[Pressure alloc] init];
    pressure.pressureScale = kPRESSUREPASCALS;
    pressure.reading = 101325;
    
    //101325pa should be 29.9212553471 Inches of Mercury.
    double result = [pressure pressureInInchesOfMercury];
    NSString *pressureResult = [NSString stringWithFormat:@"%2.9f", result];
    XCTAssertTrue([pressureResult isEqualToString:@"29.921255347"],
                   @"Converting pressure in Pa to InHg is failing.");
    
}



@end
